import 'package:flutter/material.dart';
import '../resources.dart';

/// created by hcl
/// on 2024/4/13
/// DialogTextField
/// desc
class DialogYesNo {
  static show(
      {String title = "",
      String content = "",
      String cancelText = "",
      String confirmText = "",
      VoidCallback? cancelFunc,
      VoidCallback? confirmFunc,
      bool showCancel = true,
      bool dismissible = false}) {
    Toast.showDialogWidget(
        child: _DialogYesNo(
            title: title,
            content: content,
            cancelText: cancelText,
            confirmText: confirmText,
            cancelFunc: cancelFunc,
            confirmFunc: confirmFunc,
            showCancel: showCancel),
        dismissible: dismissible);
  }
}

class _DialogYesNo extends StatefulWidget {
  String title = "";
  String content = "";
  String cancelText = "";
  String confirmText = "";
  VoidCallback? cancelFunc;
  VoidCallback? confirmFunc;
  bool showCancel = true;

  _DialogYesNo(
      {this.title = "",
      this.content = "",
      this.cancelText = "",
      this.confirmText = "",
      this.cancelFunc,
      this.confirmFunc,
      this.showCancel = true});

  @override
  State<StatefulWidget> createState() => _DialogYesNoState();
}

class _DialogYesNoState extends State<_DialogYesNo> {
  FocusNode focusNode = FocusNode();
  TextEditingController editingController = TextEditingController();
  String? error;

  @override
  Widget build(BuildContext context) {
    if (widget.cancelText.isEmpty) {
      widget.cancelText = word.cancel;
    }
    if (widget.confirmText.isEmpty) {
      widget.confirmText = word.confirm;
    }
    return Container(
      margin: EdgeInsets.symmetric(horizontal: 30.ss),
      child: Card(
        elevation: 5,
        shadowColor: ColorUtils.app_color,
        child: Container(
          decoration: BoxDecoration(
            color: ColorUtils.color_F5F5F5,
            borderRadius: BorderRadius.all(Radius.circular(16.ss)),
          ),
          child: Column(
            children: [
              SizedBox(height: 10.ss),
              widget.title.isNotEmpty
                  ? Padding(
                      padding: EdgeInsets.symmetric(horizontal: 10.ss),
                      child: Text(
                        widget.title,
                        style: medium316,
                        textAlign: TextAlign.center,
                        maxLines: 1,
                        overflow: TextOverflow.ellipsis,
                      ),
                    )
                  : const SizedBox.shrink(),
              Container(
                constraints: BoxConstraints(minHeight: 70.ss),
                padding: EdgeInsets.all(10.ss),
                child: Text(
                  widget.content,
                  style: normal714,
                  textAlign: TextAlign.center,
                ),
              ),
              SizedBox(
                height: 46.ss,
                child: Row(
                  children: [
                    widget.showCancel
                        ? Expanded(
                            child: GestureDetector(
                            behavior: HitTestBehavior.opaque,
                            onTap: () {
                              Nav.pop(result: backResult(NORMAL_CODE, ''));
                              if (widget.cancelFunc != null) {
                                widget.cancelFunc!();
                              }
                            },
                            child: Container(
                                height: 46.ss,
                                alignment: Alignment.center,
                                child: Text(widget.cancelText,
                                    style: mediumAD15)),
                          ))
                        : const SizedBox(),
                    widget.showCancel
                        ? Container(width: 1.ss, color: ColorUtils.color_F5F5F5)
                        : const SizedBox(),
                    Expanded(
                        child: GestureDetector(
                      behavior: HitTestBehavior.opaque,
                      onTap: () {
                        Nav.pop(result: backResult(NORMAL_CODE, ''));
                        if (widget.confirmFunc != null) {
                          widget.confirmFunc!();
                        }
                      },
                      child: Container(
                          height: 46.ss,
                          alignment: Alignment.center,
                          child: Text(widget.confirmText, style: mediumAD15)),
                    ))
                  ],
                ),
              )
            ],
          ),
        ),
      ),
    );
  }
}
